package top.hudk.tank.frame;

import top.hudk.tank.model.GameApplicationContext;
import top.hudk.tank.model.GameObject;

import java.awt.*;

/**
 * 作用：游戏主窗口类
 *
 * @author hudk
 * @date 2020/9/8 14:24
 */
public abstract class AbstractGameFrame extends Frame {

    /**
     * 游戏应用上下文
     */
    public GameApplicationContext gameApplicationContext;


    /**
     * 绘制画面内容
     *
     * @param g
     */
    @Override
    public abstract void paint(Graphics g);

    Image offScreenImage = null;

    @Override
    public void update(Graphics g) {
        if (offScreenImage == null) {
            offScreenImage = this.createImage(getWidth(), getHeight());
        }
        Graphics gOffScreen = offScreenImage.getGraphics();
        Color c = gOffScreen.getColor();
        gOffScreen.setColor(Color.BLACK);
        gOffScreen.fillRect(0, 0, getWidth(), getHeight());
        gOffScreen.setColor(c);
        paint(gOffScreen);
        g.drawImage(offScreenImage, 0, 0, null);
    }

    public int getGameWidth() {
        return getWidth();
    }

    public int getGameHeight() {
        return getHeight();
    }

    public abstract int maxX(GameObject o);

    public abstract int minX();

    public abstract int maxY(GameObject o);

    public abstract int minY();

}
